import * as Utils from './util.js';
import * as Ajax from './ajax.js';
import * as Inface from './interface.js';


let username = document.querySelector("#username"),
    number = document.querySelector("#number"),
    card = document.querySelector("#card"),
    context = document.querySelector('.context'),
    btns = document.querySelectorAll('button');


//开始预约
btns[1].addEventListener('click',function(){
    let uname = username.value;
   
    let num = number.value;
    
    let maibox = card.value;

    Utils.check(uname,num,maibox,context)
    Utils.setLocationStorage("uname",uname)

    
    let url = Inface.interFace.url1;
    console.log(url);
    let data = {
        phone:num,
        card:maibox,
        name:uname
    }
    // _ajax(url,data,"post",function(data1){
    //     console.log(data1);
    //     console.log(data1.result.token);
    //     localStorage.setItem("accessToken",data1.result.token);
    //     // window.location.href=`./appointment.html?access_token=${data1.result.token}`;
    //     window.location.href=`./appointment.html`;

    // })
    if(Utils.check(uname,num,maibox,context))[
        Ajax.getData(url,data,"post")
        .then((res) => {
            Utils.setLocationStorage("accessToken",res.result.token);

            window.location.href=`./appointment.html`;  
        })    
    ]
    
    //randyho 13800138001 511823198401108350

})

//我的预约
btns[0].addEventListener('click',function(){
    let uname = username.value;
   
    let num = number.value;
    
    let maibox = card.value;

    Utils.check(uname,num,maibox,context)
    if(Utils.check(uname,num,maibox,context)){
        Utils.setLocationStorage("uname",uname);

        let url = Inface.interFace.url6;
        let data = {
            phone:num,
            name:uname
        }

        Ajax.getData(url,data,"post")
            .then((res) => {
                    console.log(res.result);
                    if(res.result.length){
                        Utils.setLocationStorage("myappointment",res);

                        window.location.href=`./myappointment.html`;
                    }
                    else{
                        window.location.href=`./myappointment2.html`;
                    }
                })
        
    }


})

